package com.magicsoft.share.presenter.main;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.main.User;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.LoadingTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.view.main.ILoginView;

/**
 * Created by lyf on 2017/11/16/016.
 */

public class LoginPresenter extends BasePresenter<ILoginView> {
    public void login(String phone, String password) {
        RetrofitUtil
                .getApi(APIService.class)
                .userLogin(phone, password)
                .compose(new NetWorkTransformer<User>())
                .compose(new LoadingTransformer<User>(mContext))
                .subscribe(new SimpleObserver<User>(mCompositeDisposable) {
                    @Override
                    public void call(User user) {

                        getView().loginSuccess(user);
                    }

                    @Override
                    public void showErrorMsg(Throwable e, String errorMsg) {
                        getView().loginFail(errorMsg);
                    }
                });

    }
}
